Pasting to an existing Excel file

This is killing me... I have a file in a directory (filename). All I wanna do is open it, and paste a string into cell(1,1). I can't for the life of me figure out why this doesn't work:

OleAutoObj wbs 
OleAutoObj wb
OleAutoObj ws
OleAutoObj objCell
OleAutoArgs args = create
OleAutoObj objFont
void openExcel()
{
    string filename = "C:\Temp\file.xls"
        OleAutoObj ex = oleCreateAutoObject "Excel.Application"
        olePut(ex,"Visible",true)
        oleGet(ex,"Workbooks", wbs)
        put (args,filename"")
        oleMethod(wbs,"Open",args,wb)
        oleGet (ex, "Worksheets", args, ws)
}
void pasteString (int y, int x, string s)
{
        clear args
        put (args, y)
        put (args, x)
        oleGet (ws, "Cells", args, objCell)
        clear args
        put (args, objCell)
        copyToClipboard s
        print oleMethod (ws, "Paste",args)
}
openExcel() 
pasteString (1,1, tempStringOf tempOutput)
delete tempOutput


Any ideas? It will open my file, but nothing gets pasted and I get an error on the "oleGet (ws, "Cells", args, objCell)" line...it seems like "ws" is somehow not defined, and it's killing me.


moheganburnerIII - Fri Oct 14 17:07:39 EDT 2011

Re: Pasting to an existing Excel file
OurGuest - Sat Oct 15 02:53:06 EDT 2011

Excel would expect the strings to be surround by quotations.

Re: Pasting to an existing Excel file
moheganburnerIII - Sat Oct 15 17:36:13 EDT 2011

True, but the string gets pasted just fine when I switch a couple things around and have it open a NEW Excel wb and paste it there.

currMod = current Module
Object othero
Buffer tempO = create
for othero in entire currMod do
{
string oi = identifier othero ""
string ot = othero."Object Text" ""
tempO += oi "\t" ot
tempO += "\n"
}
OleAutoObj wbs 
OleAutoObj wb
OleAutoObj ws
OleAutoObj objCell
OleAutoArgs args = create
OleAutoObj objFont
void openExcel()
{
    OleAutoObj ex = oleCreateAutoObject "Excel.Application"
        oleGet (ex, "Workbooks", wbs) 
        oleMethod (wbs, "Add", args, wb)
        olePut(ex, "Visible", true)
        put(args, 1)
        oleGet (ex, "Worksheets", args, ws)
}
void pasteString (int y, int x, string s)
{
        clear args
        put (args, y)
        put (args, x)
        oleGet (ws, "Cells", args, objCell)
        clear args
        put (args, objCell)
        copyToClipboard s
        print oleMethod (ws, "Paste",args)
}
openExcel() 
pasteString (1,1, tempStringOf tempO)
delete tempO
}


The above pastes, but when I change the openExcel callback to:

 

void openExcel()
{
    string filename = "C:\Temp\file.xls"
        OleAutoObj ex = oleCreateAutoObject "Excel.Application"
        olePut(ex,"Visible",true)
        oleGet(ex,"Workbooks", wbs)
        put (args,filename"")
        oleMethod(wbs,"Open",args,wb)
        oleGet (ex, "Worksheets", args, ws)
}


It opens the file but doesn't paste.

 

Re: Pasting to an existing Excel file
moheganburnerIII - Mon Oct 17 10:14:13 EDT 2011

Solved my own problem by changing

void openExcel()
{
    string filename = "C:\Temp\file.xls"
        OleAutoObj ex = oleCreateAutoObject "Excel.Application"
        olePut(ex,"Visible",true)
        oleGet(ex,"Workbooks", wbs)
        put (args,filename"")
        oleMethod(wbs,"Open",args,wb)
        oleGet (ex, "Worksheets", args, ws)
}


to

 

void openExcel()
{
    string filename = "C:\Temp\file.xls"
        OleAutoObj ex = oleCreateAutoObject "Excel.Application"
        olePut(ex,"Visible",true)
        oleGet(ex,"Workbooks", wbs)
        put (args,filename"")
        oleMethod(wbs,"Open",args,wb)
        oleGet (ex, "ActiveSheet", ws)
}